using UnityEngine;
using QFramework;

namespace AsterroidX
{
	public partial class CameraController : ViewController
	{
		public static CameraController Instance;

        private void Awake()
        {
            Instance = this;
        }

        private void OnDestroy()
        {
            Instance=null;
        }

        private float mShakeA = 0;

        private float mShakeFrame = 0;

        private float mTimeSclae = 1;

        private void Update()
        {
            if(mShakeFrame>0)
            {
                mShakeFrame--;
                transform.Position2D(
                    Random.Range(0, 360).AngleToDirection2D()
                    * (mShakeFrame / 10f).Lerp(0, mShakeA));
            }
            else
            {
                transform.Position2D(Vector2.zero);
            }

            if(mTimeSclae <=1f)
            {
                mTimeSclae += Time.deltaTime * 10;
            }


            Time.timeScale=Mathf.Clamp01(mTimeSclae);
        }
        public static void Shake()
        {
            if (Instance.mShakeFrame <= 0)
            {
                Instance.mShakeA = 0.2f;
                Instance.mShakeFrame = 10;
            }
        }

        public static void BigShake()
        {
            if (Instance.mShakeFrame <= 0)
            {
                Instance.mShakeA = 0.15f;
                Instance.mShakeFrame = 20;
                Instance.mTimeSclae = 0.1f;
            }
        }

        public static void SmallRockShake()
        {
            if (Instance.mShakeFrame <= 0)
            {
                Instance.mShakeA = 0.1f;
                Instance.mShakeFrame = 10;
                Instance.mTimeSclae = 0.2f;
            }
        }
    }
}
